package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: BlueSky
 * @create: 2021-09-09 09:40
 **/
@Controller
public class IndexController {
	@Autowired
	CategoryService categoryService;

	@GetMapping({"/", "/index.html"})
	public String indexPage(Model model) {
		//TODO 1、查询出所有的一级分类
		List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();



		model.addAttribute("categorys",categoryEntities);
		//试图解析器进行拼串：
		// classpath:/templates/+返回值+ .html
		return "index";
	}


	//index/json/catalog.json
	@ResponseBody
	@GetMapping("/index/json/catalog.json")
	public Map<String, List<Catalog2Vo>> getcatalogJSON(){

		Map<String, List<Catalog2Vo>> catalogJSON = categoryService.getcatalogJSON();
		 return catalogJSON;
	}

}
